<?python
    from turbogears import identity

    from mnemoply.mass_actions import registry
    from mnemoply.controllers.MassActions import make_mass_action_url
    from sqlobject import classregistry

    def can_exec(mass_action):
        return identity.has_any_permission(
            'dba', '%s/%s' % (mass_action.target_class.getModelName(), mass_action.name))
?>

    <span xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/">
        <?python
            records = list(tab.getRecords(obj))
            records_count = len(records)
            ma_class = classregistry.findClass(ma_class_name)
            mass_actions = [x for x in registry.getActionsForClass(ma_class) if can_exec(x)]
        ?>
        <script type="text/javascript">
            no_items_selected_message = '${_("You need to select at least one record")}'
        </script>
        <span py:if="records_count == 0">No records</span>

        <span py:if="records_count > 0">

            <a href="#" onclick="toggleAll('${name}_objid_', true); return false;">
                Select all
            </a>
            |
            <a href="#" onclick="toggleAll('${name}_objid_', false); return false;">
                Clear all
            </a>

            <br />

            <span py:for="n, record in enumerate(records)">
                <input type="checkbox" name="${name}_objid_${record.id}" />
                <span>${n+1}</span>
                <a href="/${record.__class__.__name__}/${record.id}">${tab.getRecordTitle(record)}</a>
                <br />
            </span>

            <div class="tabber" py:if="len(mass_actions)">
                <div class="tabbertab" py:for="ma in mass_actions">
                    <h2>${ma.title}</h2>

                    <?python
                        ma.inject_object(obj)
                        form_code = ma.form.display(None,
                            action=make_mass_action_url(ma_class_name, ma.name),
                            form_attrs={'onsubmit':
                                "return collectIDs('" + name + "_objid_', this);"
                            },
                        )
                    ?>
                    <span>${ET(form_code)}</span>
                </div>
            </div>
        </span>
    </span>
